<template>
  <div>
    <ZgDialog
      :width="view.width"
      :top="view.top"
      :title="view.title"
      v-model="visible"
    >
      <div v-if="initLoading">
        正在初始化配置数据...
      </div>
      <div v-else>
        <div v-if="!hasInit">
          初始化配置数据失败
        </div>
        <div :style="{padding:`${layout.视图边距}px`}">
          <ZgNewPage
            ref="page"
            title=""
            addBtnName="导入新表单"
            :conditions="conditions"
            :scrollX="2000"
            :pageOpt="pageOpt"
            :batchBtns="batchBtns"
            :dataBtns="dataBtns"
            @search="onSearch"
            @admin="toAdmin"
            @batch="toBatch"

          >
            <template slot="columns">
              <a-table-column
                v-for="(column,i) in columns"
                :key="`column${i}`"
                :width="column.width"
                :title="column.label">
                <template slot-scope="record">
                  {{ record[column.code] }}
                </template>
              </a-table-column>
            </template>

          </ZgNewPage>

        </div>
      </div>
    </ZgDialog>
    <DownloadTemplate ref="downloadTemplate"></DownloadTemplate>
  </div>
</template>
<script>
import HeaderConfig from '../HeaderConfig'
import DownloadTemplate from './DownloadTemplate.vue'

export default {
  components: {
     HeaderConfig, DownloadTemplate
  },
   props: {
    view: {
      type: Object,
      default: () => {
        return {
          width: '1100px',
          top: '5%',
          height: 'auto',
          title: '东曲选煤厂_矿点发运明细表_测试'
        }
      }
    }

  },
  data () {
    return {
      visible: false,
      hasInit: true,
      initLoading: false,
      layout: {
        视图边距: 0
      },
      pageOpt: {
        showSearchBtn: false,
        showRefreshBtn: false,
        showConditionBtn: true,
        showHeaderConfig: false,
        showAttachBtn: false,
        showLayoutMode: false
      },
      columns: [
        { code: 'formName', label: '表单名称', width: 120, isShow: true },
        { code: 'formType', label: '表单类型', width: 120, isShow: true },
        { code: 'warningReceiptType', label: '预警单据类型', width: 120, isShow: true },
        { code: 'code', label: '表单CODE', width: 120, isShow: true },
        { code: 'isShow', label: '是否用户可见', width: 120, isShow: true },
        { code: 'collectStatus', label: '采集状态', width: 120, isShow: true },
        { code: 'formFormulaSetting', label: '表单公式设置', width: 120, isShow: true },
        { code: 'formTextSetting', label: '表单正文设置', width: 120, isShow: true }
      ],
      conditions: [
        { code: 'name', compType: '单行文本', label: '表单名称', defaultVal: '' },
        { code: 'code', compType: '单行文本', label: '表单CODE', defaultVal: '' }
      ],
      batchBtns: [
        { key: 1, label: '下载模板' }

      ],
      dataBtns: [
        { key: 1, name: '预警单据类型设置', icon: 'fa-cog', isShow: () => { return true } },
        { key: 2, name: '表单公式设置', icon: 'fa-gears', isShow: () => { return true } },
        { key: 3, name: '表单正文设置', icon: 'fa-cog', isShow: () => { return true } }
      ],
      attTypeArr: [
        { name: '附件1', type: '.png', limit: 10 },
        { name: '附件2', type: '.xlsx', limit: 10 }
      ]
    }
  },
  mounted () {
  },
  methods: {

    onSearch (param) {
      // 加载表头
      const list = [
        { key: '1', id: '1', formName: 'haha', formType: '男', warningReceiptType: 18, isShow: true, code: '1212' },
        { key: '2', id: '2', formName: 'haha', formType: '男', warningReceiptType: 18, isShow: true, code: '1212' },
        { key: '3', id: '3', formName: 'haha', formType: '男', warningReceiptType: 18, isShow: true, code: '1212' },
        { key: '4', id: '4', formName: 'haha', formType: '男', warningReceiptType: 18, isShow: true, code: '1212' },
        { key: '5', id: '5', formName: 'haha', formType: '男', warningReceiptType: 18, isShow: true, code: '1212' },
        { key: '6', id: '6', formName: 'haha', formType: '男', warningReceiptType: 18, isShow: true, code: '1212' }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    toAdmin (param) {
      if (param.key === 1) {
        // 预警
      }
    },
    toBatch (opt) {
      if (opt.key === 1) {
        this.$refs.downloadTemplate.open()
      }
    },
    open () {
      this.visible = true
    }

  }
}
</script>

<style lang="scss" scoped>
</style>
